package model.juliStaff.tables;

import javax.swing.*;
import java.awt.*;
import java.util.List;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
/**
 * @author Maria Julia Racca;
 */
public class TruthTAnswerCorrectionTableRenderer implements
        javax.swing.table.TableCellRenderer {

    private int result;
    private List<Integer> atomicPosition;
    private JTable answers;

    public TruthTAnswerCorrectionTableRenderer(JTable answers,
                                               List<Integer> atomicPosition) {
        this.answers = answers;
        this.atomicPosition = atomicPosition;
        this.result = -1;
    }

    public TruthTAnswerCorrectionTableRenderer(JTable correctAnswers) {
        this(correctAnswers, null);
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value,
                                                   boolean isSelected, boolean hasFocus, int row, int column) {

        String correctAnswer = (String) answers.getValueAt(row, column);

        JLabel label = new JLabel();
        label.setOpaque(true);

        if (atomicPosition != null && isAtomic(column)) {
            label.setText(correctAnswer);
            return label;

        }

        TruthTAnswerCorrectionObject answer = new TruthTAnswerCorrectionObject(
                (String) value, correctAnswer);
        String print = answer.getAnswer();

        if (answer.isEmpty()) {
            print = answer.getCorrectAnswer();

        } else if (answer.isCorrect()) {
            label.setBackground(Color.GREEN);

        } else {
            label.setBackground(Color.RED);

        }

        if (result != -1 && result == column) {
            label.setBorder(BorderFactory.createRaisedBevelBorder());
        }

        label.setText(print);
        return label;
    }

    private boolean isAtomic(int column) {

        int pos = atomicPosition.indexOf(column);
        return pos != -1;
    }

    public void setResultColumn(int i) {
        this.result = i;
    }

    public void setAtomicPosition(List<Integer> atomicPosition) {
        this.atomicPosition = atomicPosition;
    }

}

// Distintos tipos de bordes

// etiqueta.setBorder(BorderFactory.createLineBorder(Color.black));
// etiqueta.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
// etiqueta.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
// Sale para afuera //
// etiqueta.setBorder(BorderFactory.createRaisedBevelBorder());
// Se hunde //
// etiqueta.setBorder(BorderFactory.createLoweredBevelBorder());
